#include <iostream>
#include "euler/pell.hpp"
#include "euler.h"

BEGIN_PROBLEM(321, solve_problem_321)
	PROBLEM_TITLE("Swapping Counters")
	PROBLEM_ANSWER("2470433131948040")
	PROBLEM_DIFFICULTY(2)
	PROBLEM_FUN_LEVEL(3)
	PROBLEM_TIME_COMPLEXITY("k")
	PROBLEM_SPACE_COMPLEXITY("1")
	PROBLEM_KEYWORDS("game")
END_PROBLEM()

static void solve_problem_321()
{
	// x^2 - 8*y^2 =  1, (x,y) = (3,1)
	// x^2 - 8*y^2 = -7, (x,y) = (5,2), (11,4)
	typedef long long T;
	euler::pell_solution_iterator<T,int> solution1(8, 3, 1, 5, 2);
	euler::pell_solution_iterator<T,int> solution2(8, 3, 1, 11, 4);
	T sum = 0;
	for (int i = 0; i < 20; ++i, ++solution1, ++solution2)
	{
		sum += (solution1->second-1);
		sum += (solution2->second-1);
	}
	std::cout << sum << std::endl;
}
